﻿Imports BusinessRule.IBusiness
Imports DatabaseAccess.DBUtility
Imports System.Text
Imports BusinessRule.DTO
'Imports DatabaseAccess.IDAL
'Imports DatabaseAccess.DALFactory
Imports BusinessRule.Common

Public Class uLMSSpecBusiness
    Implements uLMSSpecIBusiness
    ' Private dal As IOracleDAL = uMESDalContext.instance.GetDalObject()

    Public Function GetSpecData(ByVal QueryCondition As System.Collections.Generic.Dictionary(Of String, String)) As uMESProcessResult Implements IBusiness.uLMSSpecIBusiness.GetSpecData
        Dim sb As New StringBuilder
        sb.AppendLine("SELECT s.specrevision,spb.specname,s.description,o.operationname,fa.factoryname,r.rolename,s.ncnumber,s.isspotcheck FROM spec s")
        sb.AppendLine("LEFT JOIN  specbase spb  ON s.specbaseid =spb.specbaseid ")
        sb.AppendLine("LEFT JOIN operation o ON o.operationid=s.operationid")
        sb.AppendLine("LEFT JOIN factory fa ON fa.factoryid=s.factoryid")
        sb.AppendLine("LEFT JOIN roledef r ON r.roleid=s.roleid")
        sb.AppendLine("where 1=1 ")
        If QueryCondition.Keys.Contains("specNa") = True Then
            sb.AppendFormat("and  spb.specname LIKE'%{0}%'", QueryCondition("specNa"))
        End If
        If QueryCondition.Keys.Contains("opera") = True Then
            sb.AppendFormat("AND o.operationname LIKE'%{0}%'", QueryCondition("opera"))
        End If
        'sb.AppendFormat("'%{0}%' AND o.operationname LIKE '%{1}%'", QueryCondition("specNa"), QueryCondition("opera"))
        'Dim dt As DataTable
        'dt = DatabaseHelper.Query_ReturnDatTable(sb.ToString)
        '分页开始
        '定义一个新的分页数据实例
        Dim paraPage As New uMESPagingDataDTO
        paraPage.CurrentPageIndex = Convert.ToInt32(QueryCondition("CurrentPageIndex").ToString)
        paraPage.PageSize = Convert.ToInt32(QueryCondition("PageSize").ToString)
        ' Dim strQuery As String = sb.ToString
        '将sql语句赋给分页数据的strSQL属性
        paraPage.strSQL = sb.ToString
        
        '定义一个result作为过程结果，设定初始值为 执行翻页存储过程 的结果
        Dim result As uMESProcessResult = DatabaseHelper.RunProcedureForPage(paraPage)
        Return result
    End Function

End Class
